home *** CD-ROM | disk | FTP | other *** search
- #include <windows.h>
- #include <windowsx.h>
- #include <commdlg.h>
- #include <mmsystem.h> // for timeGetTime()
- #include <stdlib.h> // for rand()
- #include "blt.h"
- #include "dib.h"
-
- #ifndef DIB_PAL_INDICES
- #define DIB_PAL_INDICES 2
- #endif
-
- #ifdef WIN32
- // unless you have Win32s 1.1 timeGetTime() does not work
- // #define timeGetTime() GetTickCount()
- #endif
-
- /*----------------------------------------------------------------------------*\
- \*----------------------------------------------------------------------------*/
-
- #define DIB_TYPE_555 100
- #define DIB_TYPE_565 101
- #define DIB_TYPE_RGB 102
- #define DIB_TYPE_BGR 103
-
- static PDIB MakeDib(int bits, int dx, int dy, UINT type);
-
- /*----------------------------------------------------------------------------*\
- \*----------------------------------------------------------------------------*/
- char szAppName[]="Blt App";
- char szAppFilter[]="Bitmaps\0*.bmp;*.dib\0All Files\0*.*\0";
-
- HINSTANCE hInstApp;
- HWND hwndApp;
- HACCEL hAccelApp;
- HPALETTE hpalApp;
- HPALETTE hpalBack;
- HRGN hrgnClip;
- BOOL fAppActive;
- BOOL gfBackPal;
- BOOL gfIdentPal=TRUE;
- BOOL gfClipping;
- BOOL gfStretch;
- BOOL gfMirror;
-
- #ifdef WIN32
- #define _export
- #define _huge
- #else
- #define SetPixelV SetPixel
- #endif
-
- struct {
- BITMAPINFOHEADER bi;
- RGBQUAD argb[256];
- } biRgb;
-
- struct {
- BITMAPINFOHEADER bi;
- WORD aw[512];
- } biPal;
-
- struct {
- BITMAP bm;
- BITMAPINFOHEADER bi;
- } ds;
-
- LPBITMAPINFOHEADER lpbiApp;
- HBITMAP hbmApp;
- HBITMAP hbmDS; // from CreateDIBSection
- HBITMAP hbmMono;
- HDC hdcApp;
- HDC hdcDS;
- int ScreenDepth;
- int TestSize = 100;
- int TestSign = 1;
-
- BITMAP bm;
- DWORD SizeImage;
- DWORD OffsetScan0;
- LPBYTE lpBitmapBits;
- LPVOID lpDibBits;
- LPBYTE BitmapTranslate;
-
- typedef void (*PDraw)(HDC hdc, int x, int y, int dx, int dy);
-
- void DrawRGB(HDC hdc, int x, int y, int dx, int dy);
- void DrawPAL(HDC hdc, int x, int y, int dx, int dy);
- void DrawIDX(HDC hdc, int x, int y, int dx, int dy);
-
- void DrawDRGB(HDC hdc, int x, int y, int dx, int dy);
- void DrawDPAL(HDC hdc, int x, int y, int dx, int dy);
- void DrawDIDX(HDC hdc, int x, int y, int dx, int dy);
-
- void DrawBLTDS(HDC hdc, int x, int y, int dx, int dy);
- void DrawBLT(HDC hdc, int x, int y, int dx, int dy);
- void DrawSBDS(HDC hdc, int x, int y, int dx, int dy);
- void DrawSB(HDC hdc, int x, int y, int dx, int dy);
- void DrawDEV(HDC hdc, int x, int y, int dx, int dy);
- void DrawXLATBLT(HDC hdc, int x, int y, int dx, int dy);
- void DrawCOPYBLT(HDC hdc, int x, int y, int dx, int dy);
-
- void DoSetBitmapBitsBitBlt(HDC hdc, int x, int y, int dx, int dy);
- void DoSetDIBitsPalBitBlt(HDC hdc, int x, int y, int dx, int dy);
- void DoSetDIBitsRgbBitBlt(HDC hdc, int x, int y, int dx, int dy);
-
- void DrawDVA(HDC hdc, int x, int y, int dx, int dy);
- BOOL InitDVA(void);
-
- void DrawDDI(HDC hdc, int x, int y, int dx, int dy);
- BOOL InitDDI(void);
-
- void DoSetDIBitsPal(HDC hdc, int x, int y, int dx, int dy);
- void DoSetDIBitsRgb(HDC hdc, int x, int y, int dx, int dy);
-
- void DoGetDIBitsPal(HDC hdc, int x, int y, int dx, int dy);
- void DoGetDIBitsRgb(HDC hdc, int x, int y, int dx, int dy);
-
- BOOL InitYES() {return TRUE;}
- void DrawNull(HDC hdc, int x, int y, int dx, int dy) {}
-
- BOOL IsWin32s()
- {
- return LOBYTE(GetVersion()) == 3 && (GetVersion() & 0x80000000l);
- }
-
- BOOL IsWin32c()
- {
- return LOBYTE(GetVersion()) >= 4 && (GetVersion() & 0x80000000l);
- }
-
- //
- // are we able to use DIB_PAL_INDICES
- //
- BOOL InitIDX() {return !IsWin32s() && !IsWin32c();}
-
- //
- // stuff to test CreateDIBSection
- //
- static HBITMAP (WINAPI *XCreateDIBSection)(HDC, LPBITMAPINFO, UINT, LPVOID FAR *, DWORD, DWORD);
- #define CreateDIBSection XCreateDIBSection
-
- #ifdef WIN32
- #define GDIMOD "GDI32"
- #else
- #define GDIMOD "GDI"
- #endif
-
- static BOOL InitDS()
- {
- (FARPROC&)XCreateDIBSection = GetProcAddress(GetModuleHandle(GDIMOD), "CreateDIBSection");
-
- if (hbmApp)
- return hbmDS != NULL;
-
- return XCreateDIBSection != NULL;
- }
-
- static UINT RandomSeed;
-
- struct {
- PDraw Draw;
- BOOL (*Init)(void);
- char * szName;
- LONG time;
- DWORD pps[20]; // pixels per second
- int count;
- } aDraw[] = {
- //
- // BitBlt and StretchBlt for comparing.
- //
- {DrawBLT,NULL, "BitBlt"},
- {DrawSB, NULL, "StretchBlt"},
- {NULL},
-
- //
- // CreateDIBSection.
- //
- {DrawBLTDS, InitDS, "BitBlt (DIBSection)"},
- {DrawSBDS, InitDS, "StretchBlt (DIBSection)"},
- {NULL},
-
- //
- // SetDIBitsToDevice
- //
- {DrawRGB,NULL, "DibToDevice (RGB)"},
- {DrawPAL,NULL, "DibToDevice (PAL)"},
- #ifdef WIN32
- {DrawIDX,InitIDX, "DibToDevice (IDX)"},
- #endif
- {NULL},
-
- //
- // StretchDIBits, should be the same
- //
- {DrawDRGB,NULL, "StretchDIBits (RGB)"},
- {DrawDPAL,NULL, "StretchDIBits (PAL)"},
- #ifdef WIN32
- {DrawDIDX,InitIDX,"StretchDIBits (IDX)"},
- #endif
- {NULL},
-
- //
- // versions of set+BitBlt
- //
- #if 0
- #ifndef WIN32
- // uses .ASM code
- {DrawXLATBLT,NULL,"XlatBits + BitBlt"},
- {DrawCOPYBLT,NULL,"CopyBits + BitBlt"},
- #endif
- #endif
- {DoSetBitmapBitsBitBlt,NULL, "SetBitmapBits + BitBlt"},
- {DoSetDIBitsPalBitBlt,NULL, "SetDIBits(PAL) + BitBlt"},
- {DoSetDIBitsRgbBitBlt,NULL, "SetDIBits(RGB) + BitBlt"},
- {NULL},
-
- #if 0
- //
- // to test the speed of these.
- //
- {DoGetDIBitsRgb,NULL, "GetDIBits (RGB)"},
- {DoGetDIBitsPal,NULL, "GetDIBits (PAL)"},
- NULL, NULL, NULL, 0, 0,
-
- {DoSetDIBitsRgb,NULL, "SetDIBits (RGB)"},
- {DoSetDIBitsPal,NULL, "SetDIBits (PAL)"},
- {NULL},
- #endif
-
- #ifndef WIN32
- //
- // DVA
- //
- {DrawDVA,InitDVA, "Direct Access"},
-
- //
- // DDI
- //
- {DrawDDI,InitDDI, "OEMBitBlt"},
- #endif
- };
-
- #define NUM_DRAW (sizeof(aDraw) / sizeof(aDraw[0]))
-
- /*----------------------------------------------------------------------------*\
- \*----------------------------------------------------------------------------*/
-
- static int iDraw;
- static PDraw Draw;
-
- void SetDraw(int i)
- {
- char ach[128];
-
- if (aDraw[i].Draw == NULL)
- return;
-
- if (!aDraw[i].Init())
- return;
-
- iDraw = i;
- Draw = aDraw[i].Draw;
- wsprintf(ach, "%s - %s - %dx%dx%d", (LPSTR)szAppName, (LPSTR)aDraw[i].szName, bm.bmWidth, bm.bmHeight, (int)biRgb.bi.biBitCount);
- SetWindowText(hwndApp, ach);
- }
-
- /*----------------------------------------------------------------------------*\
- | |
- | f u n c t i o n d e f i n i t i o n s |
- | |
- \*----------------------------------------------------------------------------*/
-
- LONG FAR PASCAL _export AppWndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
- int ErrMsg (LPSTR sz,...);
- LONG AppCommand (HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
-
- void AppExit(void);
- BOOL AppIdle(void);
- void AppOpenFile(HWND hwnd, LPSTR szFileName);
- void AppOpen(HWND hwnd, PDIB lpbi);
-
- HPALETTE CreateColorPalette(int nr,int ng, int nb);
-
- /*----------------------------------------------------------------------------*\
- | AppAbout( hDlg, uiMessage, wParam, lParam ) |
- | |
- | Description: |
- | This function handles messages belonging to the "About" dialog box. |
- | The only message that it looks for is WM_COMMAND, indicating the use |
- | has pressed the "OK" button. When this happens, it takes down |
- | the dialog box. |
- | |
- | Arguments: |
- | hDlg window handle of about dialog window |
- | uiMessage message number |
- | wParam message-dependent |
- | lParam message-dependent |
- | |
- | Returns: |
- | TRUE if message has been processed, else FALSE |
- | |
- \*----------------------------------------------------------------------------*/
- BOOL FAR PASCAL _export AppAbout(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
- {
- switch (msg)
- {
- case WM_COMMAND:
- if (LOWORD(wParam) == IDOK)
- {
- EndDialog(hwnd,TRUE);
- }
- break;
-
- case WM_INITDIALOG:
- return TRUE;
- }
- return FALSE;
- }
-
- /*----------------------------------------------------------------------------*\
- | AppInit( hInst, hPrev) |
- | |
- | Description: |
- | This is called when the application is first loaded into |
- | memory. It performs all initialization that doesn't need to be done |
- | once per instance. |
- | |
- | Arguments: |
- | hInstance instance handle of current instance |
- | hPrev instance handle of previous instance |
- | |
- | Returns: |
- | TRUE if successful, FALSE if not |
- | |
- \*----------------------------------------------------------------------------*/
- BOOL AppInit(HINSTANCE hInst,HINSTANCE hPrev,int sw,LPSTR szCmdLine)
- {
- WNDCLASS cls;
- int dx,dy;
- int i;
-
- /* Save instance handle for DialogBoxs */
- hInstApp = hInst;
-
- hAccelApp = LoadAccelerators(hInst, "AppAccel");
-
- if (!hPrev)
- {
- /*
- * Register a class for the main application window
- */
- cls.hCursor = LoadCursor(NULL,IDC_ARROW);
- cls.hIcon = LoadIcon(hInst,"AppIcon");
- cls.lpszMenuName = "AppMenu";
- cls.lpszClassName = szAppName;
- cls.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
- cls.hInstance = hInst;
- cls.style = CS_BYTEALIGNCLIENT | CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS;
- cls.lpfnWndProc = (WNDPROC)AppWndProc;
- cls.cbWndExtra = 0;
- cls.cbClsExtra = 0;
-
- if (!RegisterClass(&cls))
- return FALSE;
- }
-
- dx = GetSystemMetrics (SM_CXSCREEN) * 3 / 4;
- dy = GetSystemMetrics (SM_CYSCREEN) * 3 / 4;
-
- hwndApp = CreateWindow (szAppName, // Class name
- szAppName, // Caption
- WS_OVERLAPPEDWINDOW, // Style bits
- CW_USEDEFAULT, 0, // Position
- dx,dy, // Size
- (HWND)NULL, // Parent window (no parent)
- (HMENU)NULL, // use class menu
- hInst, // handle to window instance
- (LPSTR)NULL // no params to pass on
- );
- ShowWindow(hwndApp,sw);
-
- //
- // init every thing.
- //
- for (i=0; i<NUM_DRAW; i++)
- {
- if (aDraw[i].Init == NULL)
- aDraw[i].Init = InitYES;
- }
-
- for (i=0; i<NUM_DRAW; i++)
- {
- if (!aDraw[i].Init())
- aDraw[i].Draw = NULL;
- }
-
- if (*szCmdLine)
- AppOpenFile(hwndApp, szCmdLine);
- else
- AppOpenFile(hwndApp, "Herman");
-
- RandomSeed = (UINT)timeGetTime();
- srand(RandomSeed);
-
- hpalBack = CreateColorPalette(6,6,6);
-
- //
- // build the draw menu.
- //
- HMENU hmenu = GetSubMenu(GetMenu(hwndApp), 1);
- DeleteMenu(hmenu, MENU_DRAW, MF_BYCOMMAND);
-
- for (i=0; i<NUM_DRAW; i++)
- {
- if (aDraw[i].szName == NULL)
- AppendMenu(hmenu, MF_SEPARATOR, -1, NULL);
- else
- AppendMenu(hmenu, 0, MENU_DRAW+i, aDraw[i].szName);
- }
-
- hmenu = GetSubMenu(GetMenu(hwndApp), 2);
- AppendMenu(hmenu, MF_SEPARATOR, -1, NULL);
- AppendMenu(hmenu, 0, MENU_IDENTPAL, "Identity Palette");
- AppendMenu(hmenu, 0, MENU_BACKPAL, "Background Pal");
- AppendMenu(hmenu, 0, MENU_CLIP, "Clipping");
- AppendMenu(hmenu, 0, MENU_STRETCH, "Stretch");
- AppendMenu(hmenu, 0, MENU_MIRROR, "Mirror");
- AppendMenu(hmenu, 0, MENU_COPY, "Copy");
-
- // pick a default.
- SetDraw(0);
-
- return TRUE;
- }
-
-
- /*----------------------------------------------------------------------------*\
- | AppExit() |
- | |
- | Description: |
- | app is just about to exit, cleanup |
- | |
- \*----------------------------------------------------------------------------*/
- void AppExit()
- {
- DeleteObject(hrgnClip);
- DeleteObject(hpalBack);
- AppOpen(hwndApp, NULL);
- }
-
- /*----------------------------------------------------------------------------*\
- \*----------------------------------------------------------------------------*/
-
- #define RandRGB() RGB(rand() % 256, rand() % 256, rand() % 256)
- #define RandPT(pt, rc) ((pt).x = rc.left + (rand() % (rc.right-rc.left))), ((pt).y = rc.top + (rand() % (rc.bottom-rc.top)))
-
- RECT rcRand;
- RECT rcApp;
-
- void InitDC(HDC hdc)
- {
- if (gfBackPal)
- {
- SelectPalette(hdc, hpalBack, FALSE);
- RealizePalette(hdc);
-
- if (hpalApp)
- SelectPalette(hdc, hpalApp, TRUE);
-
- RealizePalette(hdc);
- }
- else
- {
- if (hpalApp)
- SelectPalette(hdc, hpalApp, FALSE);
-
- RealizePalette(hdc);
- }
-
- if (gfClipping && hrgnClip)
- SelectClipRgn(hdc, hrgnClip);
-
- SetStretchBltMode(hdc, COLORONCOLOR);
- GetPixel(hdc, 0, 0); //!!! hack for DVA
- }
-
- void DrawRandom(HDC hdc)
- {
- BOOL f;
- POINT pt;
- POINT ptW;
- int dx,dy;
-
- if (f = (hdc == NULL))
- {
- hdc = GetDC(hwndApp);
- InitDC(hdc);
- }
-
- if (gfStretch)
- {
- RandPT(pt, rcApp);
- RandPT(ptW,rcApp);
-
- dx = ptW.x - pt.x;
- dy = ptW.y - pt.y;
-
- if (!gfMirror)
- {
- if (dx < 0)
- pt.x = ptW.x, dx = -dx;
-
- if (dy < 0)
- pt.y = ptW.y, dy = -dy;
- }
- }
- else
- {
- RandPT(pt, rcRand);
-
- dx = bm.bmWidth;
- dy = bm.bmHeight;
- }
-
- Draw(hdc, pt.x, pt.y, dx, dy);
-
- if (f)
- ReleaseDC(hwndApp, hdc);
- }
-
- void CopyText(LPSTR pch)
- {
- HANDLE h = GlobalAlloc(GHND, lstrlen(pch)+1);
- lstrcpy((LPSTR)GlobalLock(h), pch);
- OpenClipboard(hwndApp);
- EmptyClipboard();
- SetClipboardData(CF_TEXT, h);
- CloseClipboard();
- }
-
- /*----------------------------------------------------------------------------*\
- | TimeIt() |
- \*----------------------------------------------------------------------------*/
-
- #define N 100
-
- #define FPS(time,n) \
- time ? (1000l * n / time) : 0, \
- time ? (1000000l * n / time) % 1000: 0
-
- #define XPS(x) (x) / 1000, (x) % 1000
-
- char achMsg[4096];
- char ach[256];
-
- void TimeIt(int time_this)
- {
- HDC hdc;
- LONG time;
- LONG time0;
- int i,n;
- char *pch;
- HCURSOR hcur;
- int iDrawSave;
- LONG minTime;
- int Count = N;
-
- if (bm.bmWidth <= 100)
- Count = 500;
-
- InvalidateRect(hwndApp, NULL, TRUE);
- UpdateWindow(hwndApp);
-
- hcur = SetCursor(NULL);
-
- iDrawSave = iDraw;
-
- hdc = GetDC(hwndApp);
-
- Draw = DrawNull;
- time0 = timeGetTime();
- for (i=0; i<Count; i++) DrawRandom(hdc);
- time0 = timeGetTime() - time0;
-
- for (n=0; n<NUM_DRAW; n++)
- {
- if (aDraw[n].Draw == NULL || !aDraw[n].Init())
- continue;
-
- if (time_this != -1 && time_this != n)
- continue;
-
- SetDraw(n);
- InitDC(hdc);
- DrawRandom(hdc);
-
- srand(RandomSeed);
-
- time = timeGetTime();
-
- for (i=0; i<Count; i++)
- DrawRandom(hdc);
-
- time = timeGetTime() - time - time0;
-
- aDraw[n].time = time;
- aDraw[n].count = Count;
- }
-
- SetCursor(hcur);
- ReleaseDC(hwndApp, hdc);
-
- SetDraw(iDrawSave);
-
- //
- // now make a list box, and text to put into the clipboard.
- //
- {
- HWND hwndLB;
- static int tabs[] = {100,120,140};
- RECT rc;
-
- GetWindowRect(hwndApp, &rc);
-
- wsprintf(ach, "%s - Results", (LPSTR)szAppName);
-
- hwndLB = CreateWindow("ListBox", ach,
- LBS_NOINTEGRALHEIGHT|LBS_USETABSTOPS|
- WS_POPUP | WS_VISIBLE | WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
- rc.left + (rc.right - rc.left)*1/3 /2,
- rc.top + (rc.bottom - rc.top)*1/3 /2,
- (rc.right - rc.left)*2/3,
- (rc.bottom - rc.top)*2/3,
- (HWND)hwndApp, (HMENU)NULL, hInstApp, NULL);
-
- SetWindowFont(hwndLB, GetStockObject(ANSI_VAR_FONT), TRUE);
- ListBox_SetTabStops(hwndLB, sizeof(tabs)/sizeof(tabs[0]), tabs);
-
- pch = achMsg;
-
- minTime = 0x7FFFFFF; //maxint?
-
- for (n=0; n<NUM_DRAW; n++)
- {
- if (aDraw[n].Draw == NULL || aDraw[n].time == 0)
- continue;
-
- minTime = min(minTime,aDraw[n].time);
- }
-
- ////wsprintf(ach, "%s\t%3ld.%03ld", (LPSTR)"Overhead", time0/1000, time0%1000);
- ////ListBox_AddString(hwndLB, ach);
-
- for (n=0; n<NUM_DRAW; n++)
- {
- if (aDraw[n].Draw == NULL || aDraw[n].time == 0)
- continue;
-
- wsprintf(ach, "%s\t%3ld.%03ld\t(%ld%%)", (LPSTR)aDraw[n].szName, FPS(aDraw[n].time,Count), minTime*100/aDraw[n].time);
- ListBox_AddString(hwndLB, ach);
-
- lstrcpy(pch, ach);
- lstrcat(pch, "\r\n");
- pch += lstrlen(pch);
- }
-
- CopyText(achMsg);
- }
-
- ////ErrMsg(achMsg);
- }
-
- void BigTime()
- {
- HDC hdc;
- LONG time;
- int i,n,z;
- char *pch;
- HCURSOR hcur;
- int iDrawSave;
- int Count = N;
-
- InvalidateRect(hwndApp, NULL, TRUE);
- UpdateWindow(hwndApp);
-
- hcur = SetCursor(NULL);
-
- iDrawSave = iDraw;
-
- hdc = GetDC(hwndApp);
-
- GetAsyncKeyState(VK_ESCAPE);
-
- for (z=1; z<=10; z++)
- {
- SendMessage(hwndApp, WM_COMMAND, MENU_SIZE+32*z, 0);
-
- if (bm.bmWidth <= 128)
- Count = 500;
- else
- Count = 100;
-
- for (n=0; n<NUM_DRAW; n++)
- {
- if (aDraw[n].Draw == NULL || !aDraw[n].Init())
- continue;
- #if 0
- if (aDraw[n].Draw == DoSetBitmapBitsBitBlt ||
- aDraw[n].Draw == DoSetDIBitsPalBitBlt ||
- aDraw[n].Draw == DoSetDIBitsRgbBitBlt)
- {
- aDraw[n].time = 0;
- continue;
- }
- #endif
-
- SetDraw(n);
- InitDC(hdc);
- DrawRandom(hdc);
-
- srand(RandomSeed);
-
- if (GetAsyncKeyState(VK_ESCAPE))
- goto bail;
-
- time = timeGetTime();
-
- for (i=0; i<Count; i++)
- DrawRandom(hdc);
-
- time = timeGetTime() - time;
-
- aDraw[n].time = time;
- aDraw[n].pps[z] = (DWORD)((double)bm.bmWidth * bm.bmHeight * Count * 1000 / time);
- }
- }
-
- bail:
- SetCursor(hcur);
- ReleaseDC(hwndApp, hdc);
-
- SetDraw(iDrawSave);
-
- //
- // now make a list box, and text to put into the clipboard.
- //
- {
- HWND hwndLB;
- static int tabs[] = {100,120,140,160,180,200,220,240,260,280,300,320,340,360,380,400};
- RECT rc;
-
- GetWindowRect(hwndApp, &rc);
-
- wsprintf(ach, "%s - Results", (LPSTR)szAppName);
-
- hwndLB = CreateWindow("ListBox", ach,
- LBS_NOINTEGRALHEIGHT|LBS_USETABSTOPS|
- WS_POPUP | WS_VISIBLE | WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
- rc.left + (rc.right - rc.left)*1/3 /2,
- rc.top + (rc.bottom - rc.top)*1/3 /2,
- (rc.right - rc.left)*2/3,
- (rc.bottom - rc.top)*2/3,
- (HWND)hwndApp, (HMENU)NULL, hInstApp, NULL);
-
- SetWindowFont(hwndLB, GetStockObject(ANSI_VAR_FONT), TRUE);
- ListBox_SetTabStops(hwndLB, sizeof(tabs)/sizeof(tabs[0]), tabs);
- pch = achMsg;
-
- wsprintf(ach, "%s\t %dx%d\t %dx%d\t %dx%d\t %dx%d\t %dx%d\t %dx%d\t %dx%d\t %dx%d\t %dx%d\t %dx%d",
- (LPSTR)"Pixels/mSec",
- 32*1,32*1,
- 32*2,32*2,
- 32*3,32*3,
- 32*4,32*4,
- 32*5,32*5,
- 32*6,32*6,
- 32*7,32*7,
- 32*8,32*8,
- 32*9,32*9,
- 32*10,32*10);
- ListBox_AddString(hwndLB, ach);
-
- lstrcpy(pch, ach);
- lstrcat(pch, "\r\n");
- pch += lstrlen(pch);
-
- for (n=0; n<NUM_DRAW; n++)
- {
- if (aDraw[n].Draw == NULL || aDraw[n].time == 0)
- continue;
-
- wsprintf(ach, "%s"
- "\t%3ld.%03ld"
- "\t%3ld.%03ld"
- "\t%3ld.%03ld"
- "\t%3ld.%03ld"
- "\t%3ld.%03ld"
- "\t%3ld.%03ld"
- "\t%3ld.%03ld"
- "\t%3ld.%03ld"
- "\t%3ld.%03ld"
- "\t%3ld.%03ld",
- (LPSTR)aDraw[n].szName,
- XPS(aDraw[n].pps[1]),
- XPS(aDraw[n].pps[2]),
- XPS(aDraw[n].pps[3]),
- XPS(aDraw[n].pps[4]),
- XPS(aDraw[n].pps[5]),
- XPS(aDraw[n].pps[6]),
- XPS(aDraw[n].pps[7]),
- XPS(aDraw[n].pps[8]),
- XPS(aDraw[n].pps[9]),
- XPS(aDraw[n].pps[10]));
- ListBox_AddString(hwndLB, ach);
-
- lstrcpy(pch, ach);
- lstrcat(pch, "\r\n");
- pch += lstrlen(pch);
- }
-
- CopyText(achMsg);
- }
- }
-
- /*----------------------------------------------------------------------------*\
- | WinMain( hInst, hPrev, lpszCmdLine, cmdShow ) |
- | |
- | Description: |
- | The main procedure for the App. After initializing, it just goes |
- | into a message-processing loop until it gets a WM_QUIT message |
- | (meaning the app was closed). |
- | |
- | Arguments: |
- | hInst instance handle of this instance of the app |
- | hPrev instance handle of previous instance, NULL if first |
- | szCmdLine ->null-terminated command line |
- | cmdShow specifies how the window is initially displayed |
- | |
- | Returns: |
- | The exit code as specified in the WM_QUIT message. |
- | |
- \*----------------------------------------------------------------------------*/
- int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
- {
- MSG msg;
-
- /* Call initialization procedure */
- if (!AppInit(hInst,hPrev,sw,szCmdLine))
- return FALSE;
-
- /*
- * Polling messages from event queue
- */
- for (;;)
- {
- if (PeekMessage(&msg, NULL, 0, 0,PM_REMOVE))
- {
- if (msg.message == WM_QUIT)
- break;
-
- if (hAccelApp && TranslateAccelerator(hwndApp, hAccelApp, &msg))
- continue;
-
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- else
- {
- if (AppIdle())
- WaitMessage();
- }
- }
-
- AppExit();
- return msg.wParam;
- }
-
- /*----------------------------------------------------------------------------*\
- | AppIdle() |
- | |
- | Description: |
- | place to do idle time stuff. |
- | |
- | Returns: |
- | RETURN TRUE IF YOU HAVE NOTHING TO DO OTHERWISE YOUR APP WILL BE A |
- | CPU PIG! |
- \*----------------------------------------------------------------------------*/
- BOOL AppIdle()
- {
- if (fAppActive)
- {
- //
- // we are the foreground app.
- //
- if (lpbiApp)
- {
- DrawRandom(NULL);
- return FALSE;
- }
-
- return TRUE; // nothing to do.
- }
- else
- {
- //
- // we are a background app.
- //
- return TRUE; // nothing to do.
- }
- }
-
- /*----------------------------------------------------------------------------*\
- | AppOpenFile() |
- | |
- | Description: |
- | open a file stupid |
- | |
- \*----------------------------------------------------------------------------*/
- void AppOpenFile(HWND hwnd, LPSTR szFileName)
- {
- PDIB lpbi = DibOpenFile(szFileName);
-
- if (lpbi == NULL)
- {
- ErrMsg("Cant open %s", szFileName);
- return;
- }
-
- AppOpen(hwndApp, lpbi);
- }
-
- void AppOpen(HWND hwnd, PDIB lpbi)
- {
- HDC hdc;
- LPVOID lpBits;
-
- if (hdcApp) SelectObject(hdcApp, hbmMono);
- if (hdcApp) SelectPalette(hdcApp, (HPALETTE)GetStockObject(DEFAULT_PALETTE), FALSE);
- if (hdcDS) SelectObject(hdcDS, hbmMono);
-
- if (hpalApp) DeleteObject(hpalApp);
- if (hdcApp) DeleteObject(hdcApp);
- if (hbmApp) DeleteObject(hbmApp);
- if (hdcDS) DeleteObject(hdcDS);
- if (hbmDS) DeleteObject(hbmDS);
- if (lpbiApp) DibFree(lpbiApp);
-
- hpalApp = NULL;
- lpbiApp = NULL;
- hbmApp = NULL;
- hdcApp = NULL;
-
- if (lpbi == NULL)
- return;
-
- lpbiApp = lpbi;
-
- if (!gfIdentPal)
- {
- //
- // make sure it is not a ident palette.
- //
- DibColors(lpbiApp)[0].rgbRed++;
- }
-
- //
- // get the palette
- //
- hpalApp = DibCreatePalette(lpbiApp);
-
- //
- // make this a identity palette for fast drawing.
- //
- if (lpbiApp->biBitCount == 8 && gfIdentPal && hpalApp)
- {
- MakeIdentityPalette(hpalApp);
- DibMapToPalette(lpbiApp, hpalApp);
- }
-
- //
- // convert to a bitmap
- //
- hbmApp = BitmapFromDib(lpbiApp, hpalApp, DIB_RGB_COLORS);
-
- //
- // bitmap stuff.
- //
- GetObject(hbmApp, sizeof(bm), (LPVOID)&bm);
- SizeImage = (DWORD)(UINT)bm.bmHeight * (DWORD)(UINT)bm.bmWidthBytes;
- lpBitmapBits = (LPBYTE)GlobalAllocPtr(GHND, SizeImage);
- BitmapTranslate = (LPBYTE)GlobalAllocPtr(GHND, 256);
-
- OffsetScan0 = SizeImage - bm.bmWidthBytes;
- GetBitmapBits(hbmApp, SizeImage, lpBitmapBits);
-
- lpDibBits = DibPtr(lpbiApp);
-
- //
- // we will use DIB_PAL_COLORS to draw DIBs
- //
- hmemcpy(&biRgb, lpbiApp, sizeof(biRgb)); //save RGB colors
- hmemcpy(&biPal, lpbiApp, sizeof(biRgb)); //save RGB colors
- DibSetUsage((PDIB)&biPal, hpalApp, DIB_PAL_COLORS);
-
- //
- // make memory DCs for easy access.
- //
- hdc = GetDC(NULL);
-
- ScreenDepth = GetDeviceCaps(hdc, PLANES) * GetDeviceCaps(hdc, BITSPIXEL);
-
- //
- // make a DIBSECTION
- //
- if (XCreateDIBSection != NULL)
- {
- HBITMAP hbm;
-
- if (1)
- hbmDS = CreateDIBSection(hdc, (LPBITMAPINFO)&biRgb, DIB_RGB_COLORS, &lpBits, NULL, 0);
- else
- hbmDS = CreateDIBSection(hdc, (LPBITMAPINFO)&biPal, DIB_PAL_COLORS, &lpBits, NULL, 0);
-
- if (hbmDS == NULL)
- {
- ErrMsg("Cant create DIBSection");
- goto nods;
- }
-
- GetObject(hbmDS, sizeof(ds), (LPVOID)&ds);
-
- hdcDS = CreateCompatibleDC(hdc);
-
-
- #if 0
- hbm = (HBITMAP)SelectObject(hdcDS, hbmDS);
- PatBlt(hdcDS, 0, 0, bm.bmWidth, bm.bmHeight, BLACKNESS);
- SelectObject(hdcDS, hbm);
-
- ////////hbm = (HBITMAP)SelectObject(hdcDS, hbmDS);
- // copy the bits.
- SetDIBits(hdc, hbmDS, 0, bm.bmHeight,
- lpDibBits, (LPBITMAPINFO)&biRgb, DIB_RGB_COLORS);
-
- // get back the bits to make sure it works
- GetDIBits(hdc, hbmDS, 0, bm.bmHeight,
- lpDibBits, (LPBITMAPINFO)&biRgb, DIB_RGB_COLORS);
- ////////SelectObject(hdcDS, hbm);
-
- hbm = (HBITMAP)SelectObject(hdcDS, hbmDS);
- PatBlt(hdcDS, 0, 0, bm.bmWidth, bm.bmHeight, BLACKNESS);
- SelectObject(hdcDS, hbm);
- #endif
-
- SetDIBits(hdc, hbmDS, 0, bm.bmHeight,
- lpDibBits, (LPBITMAPINFO)&biRgb, DIB_RGB_COLORS);
-
- hbm = (HBITMAP)SelectObject(hdcDS, hbmDS);
- nods:
- ;
- }
-
- for (int i=0; i<256; i++)
- BitmapTranslate[i] = i;
-
- for (i=0; i<NUM_DRAW; i++)
- aDraw[i].time = 0;
-
- hdcApp = CreateCompatibleDC(hdc);
- ReleaseDC(NULL, hdc);
-
- hbmMono = (HBITMAP)SelectObject(hdcApp, hbmApp);
-
- // do this so StretchBlt etc will work
- if (hpalApp)
- SelectPalette(hdcApp, hpalApp, FALSE);
- RealizePalette(hdcApp);
-
- SendMessage(hwndApp, WM_SIZE, 0, 0);
- }
-
- /*----------------------------------------------------------------------------*\
- | AppPaint(hwnd, hdc) |
- | |
- | Description: |
- | The paint function. Right now this does nothing. |
- | |
- | Arguments: |
- | hwnd window painting into |
- | hdc display context to paint to |
- | |
- | Returns: |
- | nothing |
- | |
- \*----------------------------------------------------------------------------*/
- AppPaint (HWND hwnd, HDC hdc)
- {
- return TRUE;
- }
-
- /*----------------------------------------------------------------------------*\
- | AppWndProc( hwnd, uiMessage, wParam, lParam ) |
- | |
- | Description: |
- | The window proc for the app's main (tiled) window. This processes all |
- | of the parent window's messages. |
- | |
- \*----------------------------------------------------------------------------*/
- LONG FAR PASCAL _export AppWndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
- {
- PAINTSTRUCT ps;
- HDC hdc;
- BOOL f;
- int i;
-
- switch (msg)
- {
- case WM_CREATE:
- break;
-
- ////////case WM_ACTIVATEAPP:
- case WM_ACTIVATE:
- fAppActive = (BOOL)wParam;
- break;
-
- case WM_TIMER:
- break;
-
- case WM_ERASEBKGND:
- break;
-
- case WM_INITMENU:
- for (i=0; i<NUM_DRAW; i++)
- {
- if (aDraw[i].Draw && aDraw[i].Init())
- EnableMenuItem((HMENU)wParam, MENU_DRAW + i, MF_ENABLED);
- else
- EnableMenuItem((HMENU)wParam, MENU_DRAW + i, MF_GRAYED);
-
- CheckMenuItem((HMENU)wParam, MENU_DRAW + i, iDraw == i ? MF_CHECKED : MF_UNCHECKED);
- }
-
- CheckMenuItem((HMENU)wParam, MENU_IDENTPAL, gfIdentPal ? MF_CHECKED : MF_UNCHECKED);
- CheckMenuItem((HMENU)wParam, MENU_BACKPAL, gfBackPal ? MF_CHECKED : MF_UNCHECKED);
- CheckMenuItem((HMENU)wParam, MENU_CLIP, gfClipping ? MF_CHECKED : MF_UNCHECKED);
- CheckMenuItem((HMENU)wParam, MENU_MIRROR, gfMirror ? MF_CHECKED : MF_UNCHECKED);
- CheckMenuItem((HMENU)wParam, MENU_STRETCH, gfStretch ? MF_CHECKED : MF_UNCHECKED);
-
- CheckMenuItem((HMENU)wParam, MENU_SIZE+16, TestSize == 16 ? MF_CHECKED : MF_UNCHECKED);
- CheckMenuItem((HMENU)wParam, MENU_SIZE+32, TestSize == 32 ? MF_CHECKED : MF_UNCHECKED);
- CheckMenuItem((HMENU)wParam, MENU_SIZE+64, TestSize == 64 ? MF_CHECKED : MF_UNCHECKED);
- CheckMenuItem((HMENU)wParam, MENU_SIZE+100,TestSize == 100 ? MF_CHECKED : MF_UNCHECKED);
- CheckMenuItem((HMENU)wParam, MENU_SIZE+200,TestSize == 200 ? MF_CHECKED : MF_UNCHECKED);
- CheckMenuItem((HMENU)wParam, MENU_SIZE+300,TestSize == 300 ? MF_CHECKED : MF_UNCHECKED);
-
- CheckMenuItem((HMENU)wParam, MENU_SIGN+1, TestSign == 1 ? MF_CHECKED : MF_UNCHECKED);
- CheckMenuItem((HMENU)wParam, MENU_SIGN-1, TestSign ==-1 ? MF_CHECKED : MF_UNCHECKED);
-
- EnableMenuItem((HMENU)wParam, MENU_IDENTPAL, ScreenDepth == (int)biRgb.bi.biBitCount ? MF_ENABLED : MF_GRAYED);
- break;
-
- case WM_COMMAND:
- return AppCommand(hwnd,msg,wParam,lParam);
-
- case WM_DESTROY:
- hAccelApp = NULL;
- PostQuitMessage(0);
- break;
-
- case WM_SIZE:
- InvalidateRect(hwnd, NULL, TRUE);
-
- GetClientRect(hwnd, &rcApp);
- GetClientRect(hwnd, &rcRand);
-
- if (lpbiApp == NULL)
- return 0L;
-
- if ((int)bm.bmWidth < rcRand.right)
- rcRand.right -= bm.bmWidth;
-
- if ((int)bm.bmHeight < rcRand.bottom)
- rcRand.bottom -= bm.bmHeight;
-
- if (hrgnClip)
- DeleteObject(hrgnClip);
-
- hrgnClip = CreateEllipticRgn(0,0,rcApp.right,rcApp.bottom);
- break;
-
- case WM_CLOSE:
- break;
-
- case WM_PALETTECHANGED:
- if ((HWND)wParam == hwnd)
- break;
-
- // fall through to WM_QUERYNEWPALETTE
-
- case WM_QUERYNEWPALETTE:
- hdc = GetDC(hwnd);
-
- if (hpalApp)
- SelectPalette(hdc, hpalApp, FALSE);
-
- f = RealizePalette(hdc);
- ReleaseDC(hwnd,hdc);
-
- if (f)
- InvalidateRect(hwnd,NULL,TRUE);
-
- return f;
-
- case WM_PAINT:
- hdc = BeginPaint(hwnd,&ps);
- AppPaint (hwnd,hdc);
- EndPaint(hwnd,&ps);
- return 0L;
- }
- return DefWindowProc(hwnd,msg,wParam,lParam);
- }
-
- /*----------------------------------------------------------------------------*\
- | AppCommand(hwnd, msg, wParam, lParam ) |
- | |
- | Description: |
- | handles WM_COMMAND messages for the main window (hwndApp) |
- | of the parent window's messages. |
- | |
- \*----------------------------------------------------------------------------*/
- LONG AppCommand (HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
- {
- char achFileName[128];
- OPENFILENAME ofn;
- int i;
-
- switch(LOWORD(wParam))
- {
- case MENU_ABOUT:
- DialogBox(hInstApp,"AppAbout",hwnd,AppAbout);
- break;
-
- case MENU_COPY:
- OpenClipboard(hwnd);
- EmptyClipboard();
- SetClipboardData(CF_DIB, HandleFromDib(DibCopy(lpbiApp)));
- CloseClipboard();
- break;
-
- case MENU_OPEN:
- achFileName[0] = 0;
-
- /* prompt user for file to open */
- ofn.lStructSize = sizeof(OPENFILENAME);
- ofn.hwndOwner = hwnd;
- ofn.hInstance = NULL;
- ofn.lpstrFilter = szAppFilter;
- ofn.lpstrCustomFilter = NULL;
- ofn.nMaxCustFilter = 0;
- ofn.nFilterIndex = 0;
- ofn.lpstrFile = achFileName;
- ofn.nMaxFile = sizeof(achFileName);
- ofn.lpstrFileTitle = NULL;
- ofn.nMaxFileTitle = 0;
- ofn.lpstrInitialDir = NULL;
- ofn.lpstrTitle = NULL;
- ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY;
- ofn.nFileOffset = 0;
- ofn.nFileExtension = 0;
- ofn.lpstrDefExt = NULL;
- ofn.lCustData = 0;
- ofn.lpfnHook = NULL;
- ofn.lpTemplateName = NULL;
-
- if (GetOpenFileName(&ofn))
- {
- AppOpenFile(hwnd,achFileName);
- }
-
- break;
-
- case MENU_EXIT:
- PostMessage(hwnd,WM_CLOSE,0,0L);
- break;
-
- case MENU_TIME:
- TimeIt(iDraw);
- break;
-
- case MENU_TIMEALL:
- TimeIt(-1);
- break;
-
- case MENU_TIMEXXX:
- BigTime();
- break;
-
- case MENU_BACKPAL:
- gfBackPal = !gfBackPal;
- PostMessage(hwnd, WM_SIZE, 0, 0);
- break;
-
- case MENU_IDENTPAL:
- gfIdentPal = !gfIdentPal;
- AppOpen(hwnd, DibCopy(lpbiApp));
- break;
-
- case MENU_CLIP:
- gfClipping = !gfClipping;
- PostMessage(hwnd, WM_SIZE, 0, 0);
- break;
-
- case MENU_MIRROR:
- gfMirror = !gfMirror;
- PostMessage(hwnd, WM_SIZE, 0, 0);
- break;
-
- case MENU_STRETCH:
- gfStretch = !gfStretch;
- PostMessage(hwnd, WM_SIZE, 0, 0);
- break;
-
- case MENU_SIGN+1:
- case MENU_SIGN-1:
- TestSign = (int)wParam - MENU_SIGN;
- PostMessage(hwnd, WM_COMMAND, MENU_TEST+(int)biRgb.bi.biBitCount, 0);
- break;
-
- case MENU_TEST+15:
- AppOpen(hwnd, MakeDib(16, TestSize, TestSize*TestSign, 0));
- break;
-
- case MENU_TEST+16:
- AppOpen(hwnd, MakeDib(16, TestSize, TestSize*TestSign, DIB_TYPE_565));
- break;
-
- case MENU_RLE+8:
- AppOpen(hwnd, MakeDib(8, TestSize, TestSize*TestSign, BI_RLE8));
- break;
-
- case MENU_RLE+4:
- AppOpen(hwnd, MakeDib(4, TestSize, TestSize*TestSign, BI_RLE4));
- break;
-
- case MENU_TEST+1:
- case MENU_TEST+4:
- case MENU_TEST+8:
- case MENU_TEST+24:
- case MENU_TEST+32:
- AppOpen(hwnd, MakeDib((int)wParam - MENU_TEST, TestSize, TestSize*TestSign, 0));
- break;
-
- default:
- i = (int)LOWORD(wParam) - MENU_SIZE;
-
- if (i >= 0 && i <= 512)
- {
- TestSize = (int)wParam - MENU_SIZE;
- SendMessage(hwnd, WM_COMMAND, MENU_TEST+(int)biRgb.bi.biBitCount, 0);
- break;
- }
-
- i = (int)LOWORD(wParam) - MENU_DRAW;
-
- if (i >= 0 && i < NUM_DRAW && aDraw[i].Draw)
- SetDraw(i);
-
- InvalidateRect(hwnd, NULL, TRUE);
- break;
- }
- return 0L;
- }
-
- /*----------------------------------------------------------------------------*\
- | ErrMsg - Opens a Message box with a error message in it. The user can |
- | select the OK button to continue |
- \*----------------------------------------------------------------------------*/
- int ErrMsg (LPSTR sz,...)
- {
- static char ach[4096];
-
- wvsprintf (ach,sz,(LPSTR)(&sz+1)); /* Format the string */
- MessageBox(hwndApp,ach,szAppName,MB_OK|MB_ICONEXCLAMATION|MB_TASKMODAL);
- return FALSE;
- }
-
- typedef void (FAR PASCAL CONVERTPROC)(
- LPVOID pd, // --> dst.
- LONG dd, // offset to start at
- LONG nd, // dst_next_scan.
- LPVOID ps, // --> source.
- LONG ds, // offset to start at
- LONG ns, // src_next_scan.
- LONG dx, // pixel count.
- LONG dy, // scan count.
- LPVOID pc); // pixel convert table.
-
- extern "C" CONVERTPROC copy_8_8, convert_8_8;
-
- void DrawDRGB(HDC hdc, int x, int y, int dx, int dy)
- {
- StretchDIBits(
- hdc,
- x,y,dx,dy,
- 0,0,
- bm.bmWidth,
- bm.bmHeight,
- lpDibBits,
- (LPBITMAPINFO)&biRgb,
- DIB_RGB_COLORS,SRCCOPY);
- }
-
- void DrawDPAL(HDC hdc, int x, int y, int dx, int dy)
- {
- StretchDIBits(
- hdc,
- x,y,dx,dy,
- 0,0,
- bm.bmWidth,
- bm.bmHeight,
- lpDibBits,
- (LPBITMAPINFO)&biPal,
- DIB_PAL_COLORS,SRCCOPY);
- }
-
- #ifdef WIN32
- void DrawDIDX(HDC hdc, int x, int y, int dx, int dy)
- {
- StretchDIBits(
- hdc,
- x,y,dx,dy,
- 0,0,
- bm.bmWidth,
- bm.bmHeight,
- lpDibBits,
- (LPBITMAPINFO)&biRgb,
- DIB_PAL_INDICES,SRCCOPY);
- }
- #endif
-
- void DrawRGB(HDC hdc, int x, int y, int dx, int dy)
- {
- SetDIBitsToDevice(hdc, x, y, dx, dy,
- 0, 0, 0, bm.bmHeight, lpDibBits,
- (LPBITMAPINFO)&biRgb, DIB_RGB_COLORS);
- }
-
- void DrawPAL(HDC hdc, int x, int y, int dx, int dy)
- {
- SetDIBitsToDevice(hdc, x, y, dx, dy,
- 0, 0, 0, bm.bmHeight, lpDibBits,
- (LPBITMAPINFO)&biPal, DIB_PAL_COLORS);
- }
-
- #ifdef WIN32
- void DrawIDX(HDC hdc, int x, int y, int dx, int dy)
- {
- SetDIBitsToDevice(hdc, x, y, dx, dy,
- 0, 0, 0, bm.bmHeight, lpDibBits,
- (LPBITMAPINFO)&biRgb, DIB_PAL_INDICES);
- }
- #endif
-
- void DrawBLT(HDC hdc, int x, int y, int dx, int dy)
- {
- // Flush cached bitmaps
- SetPixelV(hdcApp, 0, 0, 0L);
- BitBlt(hdc, x, y, dx, dy, hdcApp, 0, 0, SRCCOPY);
- }
-
- void DrawSB(HDC hdc, int x, int y, int dx, int dy)
- {
- // Flush cached bitmaps
- SetPixelV(hdcApp, 0, 0, 0L);
- StretchBlt(hdc, x, y, dx, dy,
- hdcApp, 0, 0,
- bm.bmWidth, bm.bmHeight,
- SRCCOPY);
- }
-
- void DrawBLTDS(HDC hdc, int x, int y, int dx, int dy)
- {
- BitBlt(hdc, x, y, dx, dy,hdcDS, 0, 0, SRCCOPY);
- }
-
- void DrawSBDS(HDC hdc, int x, int y, int dx, int dy)
- {
- StretchBlt(hdc, x, y, dx, dy,
- hdcDS, 0, 0,bm.bmWidth, bm.bmHeight,SRCCOPY);
- }
-
- void DoSetBitmapBitsBitBlt(HDC hdc, int x, int y, int dx, int dy)
- {
- SetBitmapBits(hbmApp, SizeImage, lpBitmapBits);
-
- StretchBlt(hdc, x, y, dx, dy,
- hdcApp, 0, 0,
- bm.bmWidth, bm.bmHeight,
- SRCCOPY);
- }
-
- void DoSetDIBitsPalBitBlt(HDC hdc, int x, int y, int dx, int dy)
- {
- SetDIBits(hdc, hbmApp, 0, bm.bmHeight, lpDibBits,
- (LPBITMAPINFO)&biPal, DIB_PAL_COLORS);
-
- StretchBlt(hdc, x, y, dx, dy,
- hdcApp, 0, 0,
- bm.bmWidth, bm.bmHeight,
- SRCCOPY);
- }
-
- void DoSetDIBitsRgbBitBlt(HDC hdc, int x, int y, int dx, int dy)
- {
- SetDIBits(hdc, hbmApp, 0, bm.bmHeight, lpDibBits,
- (LPBITMAPINFO)&biRgb, DIB_RGB_COLORS);
-
- StretchBlt(hdc, x, y, dx, dy,
- hdcApp, 0, 0,
- bm.bmWidth, bm.bmHeight,
- SRCCOPY);
- }
-
- void DoSetDIBitsPal(HDC hdc, int x, int y, int dx, int dy)
- {
- SetDIBits(hdc, hbmApp, 0, bm.bmHeight,
- lpDibBits, (LPBITMAPINFO)&biPal, DIB_PAL_COLORS);
- }
-
- void DoSetDIBitsRgb(HDC hdc, int x, int y, int dx, int dy)
- {
- SetDIBits(hdc, hbmApp, 0, bm.bmHeight,
- lpDibBits, (LPBITMAPINFO)&biRgb, DIB_RGB_COLORS);
- }
-
- void DoGetDIBitsPal(HDC hdc, int x, int y, int dx, int dy)
- {
- ////SelectObject(hdcApp, hbmMono);
- GetDIBits(hdc, hbmApp, 0, bm.bmHeight,
- lpDibBits, (LPBITMAPINFO)&biPal, DIB_PAL_COLORS);
- ////SelectObject(hdcApp, hbmApp);
- }
-
- void DoGetDIBitsRgb(HDC hdc, int x, int y, int dx, int dy)
- {
- ////SelectObject(hdcApp, hbmMono);
- GetDIBits(hdc, hbmApp, 0, bm.bmHeight,
- lpDibBits, (LPBITMAPINFO)&biRgb, DIB_RGB_COLORS);
- ////SelectObject(hdcApp, hbmApp);
- }
-
- #ifndef WIN32
- void DrawCOPYBLT(HDC hdc, int x, int y, int dx, int dy)
- {
- copy_8_8(lpBitmapBits, 0, bm.bmWidthBytes,
- lpBitmapBits, OffsetScan0, -(int)bm.bmWidthBytes,
- bm.bmWidth, bm.bmHeight, BitmapTranslate);
-
- SetBitmapBits(hbmApp, SizeImage, lpBitmapBits);
-
- StretchBlt(hdc, x, y, dx, dy,
- hdcApp, 0, 0,
- bm.bmWidth, bm.bmHeight,
- SRCCOPY);
- }
-
- void DrawXLATBLT(HDC hdc, int x, int y, int dx, int dy)
- {
- convert_8_8(lpBitmapBits, 0, bm.bmWidthBytes,
- lpBitmapBits, OffsetScan0, -(int)bm.bmWidthBytes,
- bm.bmWidth, bm.bmHeight, BitmapTranslate);
-
- SetBitmapBits(hbmApp, SizeImage, lpBitmapBits);
-
- StretchBlt(hdc, x, y, dx, dy,
- hdcApp, 0, 0,
- bm.bmWidth, bm.bmHeight,
- SRCCOPY);
- }
- #endif
-
- //
- // create a rainbow palette
- //
- HPALETTE CreateColorPalette(int nr, int ng, int nb)
- {
- LOGPALETTE *ppal;
- PALETTEENTRY *ppe;
- HPALETTE hpal = NULL;
- WORD nNumColors;
- int r,g,b;
-
- nNumColors = nr*ng*nb;
- ppal = (LOGPALETTE*)LocalAlloc(LPTR,sizeof(LOGPALETTE) + nNumColors * sizeof(PALETTEENTRY));
-
- if (!ppal)
- return NULL;
-
- ppal->palNumEntries = nNumColors;
- ppal->palVersion = 0x300;
-
- ppe = ppal->palPalEntry;
-
- for (r=0; r<nr; r++)
- for (g=0; g<ng; g++)
- for (b=0; b<nb; b++)
- {
- ppe->peRed = (BYTE)(r * 255 / (nr-1));
- ppe->peGreen = (BYTE)(g * 255 / (ng-1));
- ppe->peBlue = (BYTE)(b * 255 / (nb-1));
- ppe->peFlags = (BYTE)0;
- ppe++;
- }
-
- hpal = CreatePalette(ppal);
- LocalFree((HANDLE)ppal);
- return hpal;
- }
-
- #define RLE_ESCAPE 0
- #define RLE_EOL 0
- #define RLE_EOF 1
- #define RLE_JMP 2
- #define RLE_RUN 3
-
- #define GEN_EOL(p) { \
- *(p)++ = RLE_ESCAPE; \
- *(p)++ = RLE_EOL; }
-
- #define GEN_EOF(p) { \
- *(p)++ = RLE_ESCAPE; \
- *(p)++ = RLE_EOF; }
-
- #define GEN_RUN(p,cnt,b) if (cnt > 0) { \
- *(p)++ = (BYTE)(cnt); \
- *(p)++ = (BYTE)(b); }
-
- static PDIB MakeDib(int bits, int dx, int dy, UINT type)
- {
- int i ;
- int x ;
- int y ;
- LPBITMAPINFOHEADER lpbi;
- DWORD dwSizeImage;
- BYTE _huge *pb;
- DWORD FAR *pdw;
-
- dwSizeImage = abs(dy)*(DWORD)((dx*bits/8+3)&~3);
-
- lpbi = (LPBITMAPINFOHEADER)GlobalAllocPtr(GHND,sizeof(BITMAPINFOHEADER)+dwSizeImage + 1024);
-
- if (lpbi == NULL)
- return NULL;
-
- lpbi->biSize = sizeof(BITMAPINFOHEADER) ;
- lpbi->biWidth = dx;
- lpbi->biHeight = dy;
- lpbi->biPlanes = 1;
- lpbi->biBitCount = bits ;
- lpbi->biCompression = type >= BI_BITFIELDS ? BI_BITFIELDS : type;
- lpbi->biSizeImage = dwSizeImage;
- lpbi->biXPelsPerMeter = 0 ;
- lpbi->biYPelsPerMeter = 0 ;
- lpbi->biClrUsed = 0 ;
- lpbi->biClrImportant = 0 ;
-
- dy = abs(dy);
-
- if (bits == 4)
- lpbi->biClrUsed = 16;
-
- else if (bits == 8)
- lpbi->biClrUsed = 256;
-
- else if (type >= BI_BITFIELDS)
- // lpbi->biClrUsed = 3;
- lpbi->biClrUsed = 0;
-
- pdw = (DWORD FAR *)((LPBYTE)lpbi+(int)lpbi->biSize);
- pb = (BYTE _huge *)DibPtr(lpbi);
-
- switch (type)
- {
- case BI_RLE8:
- case BI_RLE4:
- case 0:
- if (bits == 1)
- {
- *pdw++ = 0x00000000; // 0000 black
- *pdw++ = 0x00FFFFFF; // 1111 white
- }
-
- if (bits == 4)
- {
- #if 0
- *pdw++ = 0x00000000; // 0000 black
- *pdw++ = 0x00800000; // 0001 dark red
- *pdw++ = 0x00008000; // 0010 dark green
- *pdw++ = 0x00808000; // 0011 mustard
- *pdw++ = 0x00000080; // 0100 dark blue
- *pdw++ = 0x00800080; // 0101 purple
- *pdw++ = 0x00008080; // 0110 dark turquoise
- *pdw++ = 0x00C0C0C0; // 1000 gray
- *pdw++ = 0x00808080; // 0111 dark gray
- *pdw++ = 0x00FF0000; // 1001 red
- *pdw++ = 0x0000FF00; // 1010 green
- *pdw++ = 0x00FFFF00; // 1011 yellow
- *pdw++ = 0x000000FF; // 1100 blue
- *pdw++ = 0x00FF00FF; // 1101 pink (magenta)
- *pdw++ = 0x0000FFFF; // 1110 cyan
- *pdw++ = 0x00FFFFFF; // 1111 white
- #else
- for (i=0; i<16; i++)
- *pdw++ = RGB(0,0,i*255/15);
- #endif
- }
-
- if (bits == 8)
- {
- for (i=0; i<256; i++)
- *pdw++ = RGB(i,0,0);
- }
- break;
-
- case DIB_TYPE_RGB:
- *pdw++ = 0x0000FF;
- *pdw++ = 0x00FF00;
- *pdw++ = 0xFF0000;
- break;
-
- case DIB_TYPE_BGR:
- *pdw++ = 0xFF0000;
- *pdw++ = 0x00FF00;
- *pdw++ = 0x0000FF;
- break;
-
- case DIB_TYPE_565:
- *pdw++ = 0xF800; // make a 565 DIB
- *pdw++ = 0x07E0;
- *pdw++ = 0x001F;
- break;
-
- case DIB_TYPE_555:
- *pdw++ = 0x7C00; // make a 555 DIB
- *pdw++ = 0x03E0;
- *pdw++ = 0x001F;
- break;
- }
-
- if (bits == 1)
- {
- for (y=0; y<dy; y++)
- for (x=0; x<dx; x += 8)
- {
- if (y & 1)
- *pb++ = 0xF0;
- else
- *pb++ = 0x0F;
- }
- }
- else if (bits == 4)
- {
- for (y=0; y<dy; y++)
- for (x=0; x<dx; x += 2)
- {
- i = ((x / (dx / 4)) + 4 * (y / (dy / 4)));
- i += i * 16;
- *pb++ = i;
- }
- }
- else if (bits == 8)
- {
- for (y=0; y<dy; y++)
- for (x=0; x<dx; x++)
- {
- i = (int)((DWORD)(UINT)y * 255u / (dy-1));
- *pb++ = i;
- }
-
- }
- else if (bits == 16)
- {
- for (y=0; y<dy; y++)
- for (x=0; x<dx; x++)
- {
- *pb++ = (BYTE) ((UINT)y * 31 / (dy-1));
-
- if (type == DIB_TYPE_565)
- *pb++ = (BYTE)(((UINT)x * 31 / (dx-1)) << 3);
- else
- *pb++ = (BYTE)(((UINT)x * 31 / (dx-1)) << 2);
- }
- }
- else if (bits == 24)
- {
- for (y=0; y<dy; y++)
- for (x=0; x<dx; x++)
- {
- *pb++ = (BYTE) ((DWORD)(UINT)y * 255u / (dy-1));
- *pb++ = (BYTE)~((DWORD)(UINT)x * 255u / (dx-1));
- *pb++ = (BYTE) ((DWORD)(UINT)x * 255u / (dx-1));
- }
- }
- else if (bits == 32)
- {
- for (y=0; y<dy; y++)
- for (x=0; x<dx; x++)
- {
- *pb++ = (BYTE)~((DWORD)(UINT)x * 255u / (dx-1));
- *pb++ = (BYTE) ((DWORD)(UINT)y * 255u / (dy-1));
- *pb++ = (BYTE) ((DWORD)(UINT)x * 255u / (dx-1));
- *pb++ = 0;
- }
- }
- else if (bits == 4 && type == BI_RLE4)
- {
- if (dx > 255) dx = 255;
- if (dy > 255) dy = 255;
-
- for (y=0; y<dy; y++)
- {
- GEN_RUN(pb, y/2, 0x22);
- GEN_RUN(pb, (dx-y)/2, 0xEE);
- GEN_EOL(pb);
- }
- GEN_EOF(pb);
- }
-
- else if (bits == 8 && type == BI_RLE8)
- {
- if (dx > 255) dx = 255;
- if (dy > 255) dy = 255;
-
- for (y=0; y<dy; y++)
- {
- GEN_RUN(pb, y, 0x22);
- GEN_RUN(pb, dx-y, 0xEE);
- GEN_EOL(pb);
- }
- GEN_EOF(pb);
- }
-
- return (PDIB)lpbi;
- }
-
-
- /*****************************************************************************
- *
- * dprintf() is called by the DPF macro if DEBUG is defined at compile time.
- *
- * The messages will be send to COM1: like any debug message. To
- * enable debug output, add the following to WIN.INI :
- *
- * [debug]
- * BLT=1
- *
- ****************************************************************************/
-
- #ifdef DEBUG
-
- #define MODNAME "BLT"
-
- #ifndef WIN32
- #define lstrcatA lstrcat
- #define lstrcpyA lstrcpy
- #define lstrlenA lstrlen
- #define wvsprintfA wvsprintf
- #define GetProfileIntA GetProfileInt
- #define OutputDebugStringA OutputDebugString
- #endif
-
- #define _WINDLL
- #include <stdarg.h>
-
- void FAR CDECL dprintf(LPSTR szFormat, ...)
- {
- char ach[128];
- va_list va;
-
- static BOOL fDebug = -1;
-
- if (fDebug == -1)
- fDebug = GetProfileIntA("Debug", MODNAME, TRUE);
-
- if (!fDebug)
- return;
-
- lstrcpyA(ach, MODNAME ": ");
- va_start(va, szFormat);
- wvsprintfA(ach+lstrlenA(ach),szFormat,(LPSTR)va);
- va_end(va);
- lstrcatA(ach, "\r\n");
-
- OutputDebugStringA(ach);
- }
-
- #endif
-